package com.cy.letcode.删除子文件夹;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {

    public static void main(String[] args) {
        String[] folder = new String[]{"/a/b/c", "/a/b/d", "/a/b/ca"};
        List<String> strings = new Solution().removeSubfolders(folder);
        for (String string : strings) {
            System.out.print(string + ",");
        }
    }

    public List<String> removeSubfolders(String[] folder) {
        Arrays.sort(folder);
        List<String> list = new ArrayList<>();
        String ans = "";
        boolean findFirst = false;
        for (String s : folder) {
            if ("/".equals(s)) {
                continue;
            }
            if (!findFirst) {
                ans = s;
                findFirst = true;
                list.add(ans);
                continue;
            }
            if (s.startsWith(ans) && s.charAt(ans.length()) == '/') {
                continue;
            }
            ans = s;
            list.add(ans);
        }
        return list;
    }
}